package com.cavy.platform.client.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import sun.misc.Signal;

@Component
public class AgentDaemonService implements CommandLineRunner {
    @Autowired
    private AgentRegister register;
    @Autowired
    private HeartbeatService heartbeatService;
    @Autowired
    private WebSocketService webSocketService;

    @Override
    public void run(String... strings) throws Exception {
        //1,注册
        register.register();
        //2,连接到服务器
        webSocketService.connectServer();
        //3,开启心跳
        heartbeatService.start();
        //https://www.cnblogs.com/wardensky/p/4107719.html
        Signal.handle(new Signal("TERM"), heartbeatService);
        Signal.handle(new Signal("INT"), heartbeatService);
//        Signal.handle(new Signal("USR1"), heartbeatService);
//        Signal.handle(new Signal("USR2"), heartbeatService);
        //阻塞,等待sign
//        heartbeatService.join();
    }
}
